package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.utils.resources.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.dubbo.config.annotation.Reference;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@RestController   //  @Controller +@ResponseBody
@Api(tags = "检查组管理")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    //   查询所有检查项 。。。
    @GetMapping("checkgroup/findAll")
    @ApiOperation(value = "查询检查组",notes = "查询所有检查组信息")
       public Result findAll(){
        try {
            List<CheckGroup> list = checkGroupService.list();
            return  new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }

     @PostMapping("checkgroup/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        try {
           PageResult pageResult =  checkGroupService.findPage(queryPageBean);
            return  new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,pageResult);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }

    @GetMapping("checkgroup/findCheckItemInfoByGroupId/{id}")
    public Result findCheckItemInfoByGroupId(@PathVariable("id") int id){
        try {
             Map map  =  checkGroupService.findCheckItemInfoByGroupId(id);
            return  new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }


    @PostMapping("checkgroup/add")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO){
        try {
              checkGroupService.saveCheckGroup(checkGroupDTO);
              return  new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }

//    @GetMapping("checkitem/findCheckItemById/{id}")
//    public Result findCheckItemById(@PathVariable("id") int id){
//        try {
//            CheckItem checkItem = checkItemService.getById(id);
//            return  new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS,checkItem);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return  new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
//        }
//    }

//    @DeleteMapping("checkitem/deleteCheckItemById/{id}")
//    public Result  deleteCheckItemById(@PathVariable("id") int id){
//        try {
//             CheckItem checkItem = new CheckItem();
//             checkItem.setIs_delete(1);  //  逻辑删除
//             checkItem.setId(id);
//             checkItemService.updateById(checkItem);
//            return  new Result(true, MessageConstant.DELETE_CHECKITEM_SUCCESS);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return  new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
//        }
//    }

}
